package org.cms.util;

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

@Data
public class RUtil<T> {

    @Schema(description = "状态")
    private Integer code;
    @Schema(description = "消息")
    private String msg;
    @Schema(description = "数据")
    private T data;

    private static final Integer SUCCESS_CODE = 200;
    private static final Integer ERROR_CODE = -1;
    private static final String SUCCESS_MSG = "请求成功";
    private static final String FAIL_MSG = "请求失败";

    public RUtil(Integer code, String msg, T data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static <T> RUtil<T> success() {
        return new RUtil<>(SUCCESS_CODE, SUCCESS_MSG, null);
    }

    public static <T> RUtil<T> success(String msg) {
        return new RUtil<>(SUCCESS_CODE, msg, null);
    }

    public static <T> RUtil<T> success(String msg, T data) {
        return new RUtil<>(SUCCESS_CODE, msg, data);
    }

    public static <T> RUtil<T> success(T data) {
        return new RUtil<>(SUCCESS_CODE, SUCCESS_MSG, data);
    }

    public static <T> RUtil<T> fail() {
        return new RUtil<>(ERROR_CODE, FAIL_MSG, null);
    }

    public static <T> RUtil<T> fail(String msg) {
        return new RUtil<>(ERROR_CODE, msg, null);
    }

    public static <T> RUtil<T> fail(String msg, T data) {
        return new RUtil<>(ERROR_CODE, msg, data);
    }

}
